import { constantRoutes, asyncRouter } from '@/router'
const state = {
  routes: constantRoutes
}

const mutations = {
  setRouters(state, newRouter) {
    state.routes = [...constantRoutes, ...newRouter]
  }
}

const actions = {
  // 筛选权限路由
  filterRouter({ commit }, menus) {
    const routers = []
    // console.log('menus=>', menus)
    if ((menus.is_admin - 0) === 1) {
      // console.log('ok')
      routers.push(...asyncRouter)
      // console.log(routers)
    }
    commit('setRouters', routers)
    return routers
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
